<template>
  <!-- van-nav-bar
     title:中间标题
     left-text:左边文本
     right-text:右边文本
     @click-left:左边点击
     @click-right:右边点击
     slot="left/title/rigjht"
 -->
  <van-nav-bar
    class="hmNavBar"
    @click-left="$router.push(path)"
    @click-right="clickRight"
  >
    <template #left v-if="showLeft">
      <i class="iconfont f44">&#xe637;</i>
    </template>
    <template #title>
      <div class="title">
        {{ title }}
      </div>
    </template>
    <template #right>
      <div class="right">
        {{ right }}
      </div>
    </template>
  </van-nav-bar>
</template>
<script>
export default {
  name: 'hmNavBar',
  // props: ['title', 'right', 'path'],
  // type类型[String,Number]
  props: {
    title: {
      type: String,
      default: undefined
    },
    right: {
      type: String,
      default: undefined
    },
    path: {
      type: String,
      default: undefined
    },
    showLeft: {
      type: Boolean,
      default: true
    }
  },
  methods: {
    clickRight () {
      // 子触发父方法  1:this.$parent

      // this.$parent.save()
      /*
      2:通过$emit 
      a:在子组件标签上定义一个相应的方法 @子组件方法名=父组件方法
      b:在子组件内触发该方法  this.$emit("子组件方法名")
      */
      //  公有组件:放在components里面的优先用emit处理,
      // 私有的,只是当前页面使用一下,怎么简单怎么来
      // this.$parent.rightClick()
      this.$emit('rightClick')
      // window.console.log(this.$parent)
    }
  }
}
</script>

<style lang="less" scoped>
.hmNavBar {
  &::v-deep .van-nav-bar__left,
  &::v-deep .van-nav-bar__right {
    padding: 0;
  }
  .f44 {
    font-size: 44px;
  }
  .title {
    font-size: 18px;
    font-family: PingFangSC, PingFangSC-Semibold;
    font-weight: 600;
    text-align: center;
    color: #222222;
    line-height: 25px;
    letter-spacing: 0px;
  }
  .right {
    font-size: 14px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: right;
    color: #181a39;
    line-height: 20x;
    letter-spacing: 0px;
    padding-right: 15px;
  }
}
</style>
